// pages/device/orderWorkflow/orderWorkflow.js
import {
  _globle
} from '../../../utils/globle.js'
import lwx from '../../../utils/lwx.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    select: 0,
    workflowDtoList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // this.defule(options)
    this.loadData();
  },
  loadData: function () {
    var that = this;
    lwx.request({
      url: "workflow.list",
      data: {
        companyId: 2,
        partyId: 2,
        workflowType: "QUEUE"
      }
    }).then(res => {
      console.log(res)
      if (res.data.code == '0') {
        that.setData({
          workflowDtoList: res.data.workflowDtoList
        })
      }
    }).catch(err => {
      console.log('err' + err);
    })
  },
  defule: function(e) {
    this.data.workflowDtoList[e.select].check = true;
    this.setData({
      select: [e.select],
      workflowDtoList: this.data.workflowDtoList
    })
  },
  switchChange: function(e) {
    // console.log(array[e.currentTarget.dataset.index])
    var workflowDtoList = this.data.workflowDtoList;
    for (var i = 0; i < workflowDtoList.length; i++) {
      if (i == e.currentTarget.dataset.index) {
        workflowDtoList[i].check = true;
      } else {
        workflowDtoList[i].check = false;
      }
    }
    this.setData({
      workflowDtoList: workflowDtoList,
      select: e.currentTarget.dataset.index
    })
  },
  keepit: function() {
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2];
    prevPage.setData({
      orderArrayData: this.data.workflowDtoList[this.data.select]
    })
    wx.navigateBack({
      delta: 1,
    })
  },

  // workflowDtoList
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})